<template>
    <div>
              <!-- 新增/修改职位表单 -->
        <el-dialog
            :close-on-click-modal = "false"
            ref = "dialog"
            v-dialogDrag
            class="posClass"
            width="640px"
            title = "修改立项分析"
            :visible.sync="dialogVisible"
            :before-close = "beforeClose"
            center>
            <el-form ref="form" :model="form" :rules="rules" class="paddLR20 marT10" :inline="true" label-width = "110px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="立项分析编号" prop = "num" class="posRelative">
                            <el-input v-model.trim="form.num" class="inputTxtWrapper" maxlength="50" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="名称" prop = "name">
                            <el-input v-model.trim="form.name" class="inputTxtWrapper" maxlength="50" placeholder="请输入名称"></el-input>
                        </el-form-item>
                        <!-- <el-form-item label="需求开始时间" prop = "startTime">
                            <el-date-picker
                            class="inputTxtWrapper"
                            v-model="form.startTime"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择日期时间"
                            align="right">
                            </el-date-picker>
                        </el-form-item> -->
                        <!-- <el-form-item label="项目负责人" prop = "liableUserId">
                            <el-select class="inputTxtWrapper" v-model="form.liableUserId" placeholder="请选择项目负责人">
                                <el-option
                                v-for="item in userList"
                                :key="item.id"
                                :disabled="item.isDisabled"
                                :label="item.user_name"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item> -->
                    </el-col>
                </el-row>
		    </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click.stop.native = "beforeClose">取消并关闭</el-button>
                <el-button type="primary" @click="editProAnaly('form')">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import http from '@/assets/js/http'
import _g from '@/assets/js/global'

export default {
    props:{
        dialogVisible:{
            type:Boolean,
            default:true
        },
        // userList:{
        //     type:Array,
        //     required:true
        // },
        currRowRecord:{
            type:Object,
            default : null,
        }
    },
    mixins: [http],
    watch: {
        currRowRecord(newVal,oldVal){
            if(newVal !== null){
                this.form.num = newVal.pro_analy_num
                this.form.name = newVal.pro_analy_name
                // this.form.startTime = newVal.start_time
                this.form.liableUserId = newVal.liable_user_id
            }
        },
        deep : true
    },
    created () {
    },
    data(){

        return{
             /* 编辑立项分析表单 */
            form:{
                num:'',//编号
                name : '',//..立项分析名称
                // startTime : '',//..需求分析开始时间
                // liableUserId : '',//  所属项目负责人id
                inheritProId : '',//..继承的项目id
            },

            rules: {
                num : [
                    { required: true, message: '请输入立项分析编号', trigger: 'blur' },
                ],
                name : [
                    { required: true, message: '请输入名称', trigger: 'blur' },
                ],
                // liableUserId : [
                //     { required: true, message: '请选择项目负责人', trigger: 'blur' },
                //     // {validator:validateLiableUserId, trigger:'blur'}
                // ],
                startTime : [
                    { required: true, message: '请选择需求分析开始时间', trigger: 'blur' },
                ],
            }

        }
    },
    methods: {
        /* 关闭弹框 */
        beforeClose(str,index) {
            this.$refs.form.resetFields();
            this.$emit('hideEditProAnalyDialog',str)
        },
        /* 修改立项分析 */
        editProAnaly(){

            const that = this

            const formData = new FormData()

            that.$refs.form.validate((valid) => {
                if(valid){
                    formData.append('num',that.form.num)
                    formData.append('name',that.form.name)
                    // formData.append('startTime',that.form.startTime)
                    // formData.append('liableUserId',that.form.liableUserId)
                    formData.append('proAnalyId',that.currRowRecord.id)

                     that.$confirm('是否确认?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        center: true
                    }).then(() => {
                            _g.showLoading('提交中')
                            that.apiPost('admin/task/editProAnaly', formData).then((res) => {
                                _g.showLoading().close()
                                if(typeof res === 'string'){
                                    res = JSON.parse(res)
                                }
                                if (res.code != 200) {
                                    that.handleError(res)
                                } else {
                                    if(res.data.isSuccess === 0){             //  成功
                                        _g.toastMsg("success", res.message)
                                        that.beforeClose('更新立项分析成功',that.currRowRecord.index)
                                    }else if(res.data.isSuccess === 2){
                                        _g.toastMsg("warning", res.message)
                                    }else if(res.data.isSuccess === 1){
                                        _g.toastMsg("error", res.message)
                                    }
                                }
                            })
                    }).catch(() => {});
                }
            })
        },
    },
}
</script>

<style lang="less" scoped>

</style>


